package labrom.usage.shared;

import java.io.Serializable;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * This is a Usage Data Item. It represents a single action occurrence
 * in the client application.
 * 
 * Each client instance must be assigned a GUID and must store it in order to 
 * put into every Usage Data Item it creates.
 * 
 * @author Romain Laboisse
 *
 */
@PersistenceCapable
public class Udi implements Serializable, IsSerializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused")
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;
	
	/**
	 * Time stamp when the action occurred. 
	 */
	@Persistent
	private long timestamp;
	
	/**
	 * Action type ID.
	 */
	@Persistent
	private long typeId;

	/**
	 * Client GUID's most significant bits.
	 */
	@Persistent
	private long guidMsb;

	/**
	 * Client GUID'sleast significant bits.
	 */
	@Persistent
	private long guidLsb;

	/**
	 * Client app version.
	 */
	@Persistent
	private int appVersion;

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	public long getTypeId() {
		return typeId;
	}

	public void setTypeId(long typeId) {
		this.typeId = typeId;
	}

	public long getGuidMsb() {
		return guidMsb;
	}

	public void setGuidMsb(long guidMsb) {
		this.guidMsb = guidMsb;
	}

	public long getGuidLsb() {
		return guidLsb;
	}

	public void setGuidLsb(long guidLsb) {
		this.guidLsb = guidLsb;
	}

	public int getAppVersion() {
		return appVersion;
	}

	public void setAppVersion(int appVersion) {
		this.appVersion = appVersion;
	}
	

//	public UUID getGuid() {
//		return new UUID(getGuidMsb(), getGuidLsb());
//	}
//	
//	public void setGuid(UUID guid) {
//		setGuidMsb(guid.getMostSignificantBits());
//		setGuidLsb(guid.getLeastSignificantBits());
//	}
	
	public void setTimestampNow() {
		setTimestamp(System.currentTimeMillis());
	}
}
